package io.renren.service.impl;

import com.alibaba.fastjson.JSONObject;
import io.renren.dao.DictUtilsDao;

import io.renren.entity.SysUserEntity;
import io.renren.service.DictUtilsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

@Transactional(propagation= Propagation.REQUIRED)
@Service("dictUtilsService")
public class DictUtilsServiceImpl implements DictUtilsService {

	@Autowired
	private DictUtilsDao dictUtilsDao;

	public Map<String, Object> getDictList(JSONObject params) {
		String [] dicttype = params.get("dicttype").toString().split(",");
		Map<String, Object> map = new HashMap<>();
		for (String dcitlist : dicttype) {
			List<HashMap<String, Object>> list=new ArrayList<HashMap<String, Object>>();
			HashMap temp = new HashMap();
			temp.put("id","");
			temp.put("value","");
			list.add(temp);
			list.addAll(dictUtilsDao.getDictList(dcitlist));
			map.put(dcitlist,list);
		}
		return map;
	}

	@Override
	public String getValueByLabel(String Label) {
		return dictUtilsDao.getValueByLabel(Label);
	}

}
